package main

import (
	"flag"
	"fmt"
	"go.etcd.io/bbolt"
	"log"
	"videofox/file"
)

func main() {
	var (
		dbpath string
	)

	// &var, opt, default value, description
	flag.StringVar(&dbpath, "d", "./videofox.db", "database path")

	flag.Parse()

	if !file.Exist(dbpath) {
		fmt.Printf("not found database: %v\n", dbpath)
		return
	}
	fmt.Printf("database: %v\n", dbpath)

	db, err := bbolt.Open(dbpath, 0600, nil)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	err = db.View(func(tx *bbolt.Tx) error {
		return tx.ForEach(func(name []byte, b *bbolt.Bucket) error {
			fmt.Println("Bucket:", string(name))
			return nil
		})
	})
	if err != nil {
		log.Fatal(err)
	}
}
